.request-decision.mt-n1
  = form_with(url: request_changerequest_path, html: { id: "request_handle_form_#{bs_request.id}" }, local: true) do |form|
    = hidden_field_tag(:number, @bs_request.number)
    = hidden_field_tag(:commentable_type, @bs_request.class.name)
    = hidden_field_tag(:commentable_id, @bs_request.id)
    .pb-2{ 'data-canned-controller': '' }
      - if policy(Comment.new(commentable: @bs_request)).locked?
        .alert.alert-warning.mt-2{ role: 'alert' }
          Commenting on this is locked.
          - if CommentLockPolicy.new(User.session, @bs_request).create?
            = helpers.comment_lock_alert(@bs_request)
      - decision_placeholder = "Write your comment or decision...(markdown is only supported for comments, not for decisions)"
      = render WriteAndPreviewComponent.new(form: form, preview_message_url: preview_comments_path, canned_responses_enabled: true,
                                            message_body_param: 'comment[body]',
                                            text_area_attributes: { object_name: 'reason', id_suffix: 'new_comment',
                                            placeholder: decision_placeholder})
      .mt-2#decision-buttons-row
        %div
          - if policy(Comment.new(commentable:@bs_request)).create?
            = submit_tag 'Add comment', class: 'btn btn-outline-primary me-2', data: { disable_with: 'Creating comment...' }, name: 'commented'
        %div
          - if policy(@bs_request).revoke_request?
            = submit_tag('Revoke request', name: 'revoked', class: 'btn btn-danger ms-2',
                          title: 'Cancel the request', data: { confirm: "Revoke this request?" })
          - if policy(@bs_request).decline_request?
            = submit_tag('Decline request', name: 'declined', class: 'btn btn-danger ms-2',
                          title: 'Reject the changes.', data: { confirm: "Decline this request?\n\n#{@package_maintainers_hint}" })
          - if policy(@bs_request).accept_request?
            .btn-group.ms-2
              - if show_forward? # Accept and Forward goes by default when possible
                = submit_tag('Accept and forward', name: 'accepted',
                            class: 'btn btn-primary',
                            id: 'accept-and-forward-requests',
                            title: "Commit the changes and create a request to forward the changes to #{forwards_names}",
                            data: { confirm: 'Accept and forward this request?' })
              - else
                = submit_tag('Accept request', name: 'accepted', class: 'btn btn-primary',
                            data: confirmation, title: "Commit changes to #{target_names}.")
              - if show_forward? || show_add_creator_as_maintainer?
                = button_tag('', type: 'button', class: 'btn btn-primary dropdown-toggle dropdown-toggle-split border-start',
                              data: { 'bs-toggle': 'dropdown'}, aria: { 'haspopup': 'true', 'expanded': 'false' }, title: 'Accept options')
                .dropdown-menu#request-accept-buttons-dropdown-menu
                  .list-group.list-group-flush
                    - if show_forward? # Accept and Forward was displayed by defualt, so Accept request should be displayed in the dropdown
                      = button_tag(type: 'submit', value: 'Accept request',
                        name: 'accepted', id: 'accept-requests',
                        class: 'btn btn-primary text-start rounded-0 list-group-item',
                        data: { confirm: 'Accept and this request?' }) do
                        %b Accept request
                        %br
                        %i Only commit the changes
                    - if show_add_creator_as_maintainer?
                      = button_tag(type: 'submit', value: 'Accept and make maintainer',
                                  name: 'accepted', id: 'accept-and-make-maintainer',
                                  class: 'btn btn-primary text-start rounded-0 list-group-item',
                                  data: { confirm: "Accept and make the request creator a maintainer?" }) do
                        %b Accept and make maintainer
                        %br
                        %i Commit the changes and make #{@bs_request.creator} a maintainer of #{target_names}
                    - if show_add_creator_as_maintainer? && show_forward?
                      -# haml-lint:disable LineLength
                      = button_tag(type: 'submit', value: 'Accept, make maintainer and forward',
                                  name: 'accepted', id: 'accept-make-maintainer-and-forward-requests',
                                  class: 'btn btn-primary rounded-0 text-start list-group-item',
                                  data: { confirm: "Do you really want to accept, forward this request and make the request creator maintainer of the target?" }) do
                        %b Accept, make maintainer and forward
                        %br
                        %i Commit the changes, make #{@bs_request.creator} a maintainer of #{target_names}, and create a request to forward the changes to #{forwards_names}
                      -# haml-lint:enable LineLength
          - if policy(@bs_request).reopen_request?
            = submit_tag 'Reopen request', name: 'new', class: 'btn btn-warning ms-2', data: { confirm: "Reopen this request?" }

:javascript
  attachPreviewMessageOnCommentBoxes();

  // Check the proper checkbox behind the scene on different type of accept submit
  $('#accept-and-make-maintainer').on('click', function(){
    $('input[name=add_submitter_as_maintainer_0]').prop('checked', 'checked');
  });
  $('#accept-and-make-maintainer-and-forward').on('click', function(){
    $('input[name=add_submitter_as_maintainer_0]').prop('checked', 'checked');
  });

  // Only require the text if submitting a comment, declining or reopening
  $('[id^="request_handle_form_"]').find('[name=revoked], [name=accepted]').on('click', function () {
    $('#new_comment_body').removeAttr('required');
  });
  $('[id^="request_handle_form_"]').find('[name=new], [name=declined], [name=commented]').on('click', function () {
    $('#new_comment_body').attr('required', 'required');
  });
